﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using umbraco.editorControls;

namespace Designit.Umb.DataTypes.Video
{
    public class PrevalueEditor : System.Web.UI.WebControls.PlaceHolder, umbraco.interfaces.IDataPrevalue
    {
        private umbraco.cms.businesslogic.datatype.BaseDataType dataType;
        //private CheckBox _registerFancybox;

        public PrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType DataType)
        {
            dataType = DataType;
            //SetupChildControls();
        }

        //private void SetupChildControls()
        //{
        //    _registerFancybox = new CheckBox {ID = "cbRegisterFancybox", CssClass = "umbEditorCheckBox"};

        //    Controls.Add(_registerFancybox);
        //}
        
        public System.Web.UI.Control Editor
        {
            get { return this; }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //if(!Page.IsPostBack)
            //{
            //    if (Configuration != null)
            //    {
            //        _registerFancybox.Checked = (int)Configuration == 1;
            //    }
            //    else
            //        _registerFancybox.Checked = true;
            //}
        }

        public void Save()
        {
            //dataType.DBType =
            //    (umbraco.cms.businesslogic.datatype.DBTypes)
            //    Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), DBTypes.Ntext.ToString(), true);

            //var data = !_registerFancybox.Checked ? 0 : 1;

            //SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlHelper.CreateParameter("@dtdefid", dataType.DataTypeDefinitionId));

            //SqlHelper.ExecuteNonQuery(
            //    "insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')",
            //    SqlHelper.CreateParameter("@dtdefid", dataType.DataTypeDefinitionId),
            //    SqlHelper.CreateParameter("@value", data));
        }

        //protected override void Render(HtmlTextWriter writer)
        //{

        //    writer.WriteLine("<table>");

        //    writer.Write("<tr><th>Register Fancybox script:</th><td>");

        //    _registerFancybox.RenderControl(writer);

        //    writer.Write("</td></tr>");

        //    writer.Write("</table>");

        //}

        //public object Configuration
        //{
        //    get
        //    {
        //        var conf = SqlHelper.ExecuteScalar<object>("select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid", SqlHelper.CreateParameter("@datatypenodeid", dataType.DataTypeDefinitionId));

        //        return conf ?? null;
        //    }

        //}

        //public static ISqlHelper SqlHelper
        //{

        //    get
        //    {

        //        return Application.SqlHelper;

        //    }

        //}

    }
}